package kz.pompei.OneGwt.ifaces.widget.gwtadapters;

import kz.pompei.OneGwt.ifaces.util.Handler;
import kz.pompei.OneGwt.ifaces.util.HandlerKiller;
import kz.pompei.OneGwt.ifaces.widget.BoolWidget;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.CheckBox;

public class CheckBox_impl_BoolWidget implements BoolWidget {
  
  private final CheckBox checkBox;
  
  public CheckBox_impl_BoolWidget(CheckBox checkBox) {
    this.checkBox = checkBox;
  }
  
  @Override
  public HandlerKiller addChangeHandler(final Handler handler) {
    final HandlerRegistration hr = checkBox
        .addValueChangeHandler( new ValueChangeHandler<Boolean>() {
          @Override
          public void onValueChange(ValueChangeEvent<Boolean> event) {
            handler.handle();
          }
        } );
    return new HandlerKiller() {
      @Override
      public void killHandler() {
        hr.removeHandler();
      }
    };
  }
  
  @Override
  public void setVisible(boolean visible) {
    checkBox.setVisible( visible );
  }
  
  @Override
  public void setEnabled(boolean enabled) {
    checkBox.setEnabled( enabled );
  }
  
  @Override
  public void setFocus(boolean focused) {
    checkBox.setFocus( focused );
  }
  
  @Override
  public boolean isit() {
    return checkBox.getValue();
  }
  
  @Override
  public void set(boolean value) {
    checkBox.setValue( value );
  }
}
